package com.shawn.springboot.integeration.netty.server.initializer;

import com.shawn.springboot.integeration.netty.codec.RpcDecoder;
import com.shawn.springboot.integeration.netty.codec.RpcEncoder;
import com.shawn.springboot.integeration.netty.msg.Request;
import com.shawn.springboot.integeration.netty.msg.Response;
import com.shawn.springboot.integeration.netty.server.handler.MyServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

/**
 * @author zhangjian
 * @title: MyServerInitializer
 * @projectName 12-springboot学习
 * @description: 服务端
 * @date 2021/4/2810:56
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) {
        //  设置自定义解码器
        socketChannel.pipeline().addLast(new RpcDecoder(Request.class));
        //  设置自定义编码器
        socketChannel.pipeline().addLast(new RpcEncoder(Response.class));
        //  设置自定义消息处理器
        socketChannel.pipeline().addLast(new MyServerHandler());
    }
}
